package bosVM2.meta;

import java.util.Map.Entry;
import java.util.Set;

import bosVM2.meta.Objects.BosClass;
import bosVM2.meta.Objects.BosMethod;
import bosVM2.util.Map;

public class MetaData {	
	//Integer to string Map
	private Map<Integer,String> stringMap = new Map<Integer,String>();
	public String getString(Integer i)
	{
		return stringMap.get(i);
	}
	public Integer getStringId(String s) {
		for(Entry<Integer, String> e: stringMap.Entries())
		{
			if(e.getValue().equals(s))
			{
				return e.getKey();
			}
		}
		int i = stringMap.size(); 
		stringMap.put(i,s);
		return i;
	}
	
	//Class, method, field, and array meta data.
	private Map<String, BosClass> classes = new Map<String,BosClass>();
	
	public BosClass getMetaClass(String b) {
		return classes.get(b);
	}
	
	public void addMetaClass(BosClass b)//TODO
	{	
		classes.put(b.getClassName(), b);
	}
	
	public boolean classKnown(String clss) {
		if(classes.containsKey(clss)) { return true; }
		else { return false; }
	}
	
	public Set<String> getClasses()
	{
		return classes.getKeys();
	}
	//Get method
	public BosMethod getMetaMethod(String classname,String method)
	{
		return new BosMethod(classes.get(classname).getMethod(method));
	}
	
	//get method ins at pc
	public Object[] getMethodInsAtPc(String classname,String method,int pc)	
	{
		return getMetaMethod(classname,method).instructionAt(pc);
	}
	//Util
	public String toString()
	{
		return "MetaData: " + " classes: " + classes;
	}
	
}
